﻿#pragma once
#define _USE_MATH_DEFINES
#include <cmath>
//M_PI未定义和M_PI_2未定义添加#include<QtMath>
#include<QtMath>
#ifndef RISKGIS_H
#define RISKGIS_H
#include <QMainWindow>
//qgs头文件
#include<qgsproject.h>
#include<qgsapplication.h>
#include<qgsmapcanvas.h>
#include<qgslayertreeview.h>
#include<qgsdockwidget.h>
#include<qgsmaptool.h>
#include<qgsmaptoolpan.h>
#include<qgsmaptoolzoom.h>
#include<qgslayertreemapcanvasbridge.h>
#include<qgslayertree.h>
#include<qgsmessagebar.h>
#include<qgsscalecombobox.h>
#include<qprogressbar.h>
#include<qgsmapsettings.h>
#include<qgsmapoverviewcanvas.h>
#include<qgsrasterminmaxorigin.h>
#include<qgsbrightnesscontrastfilter.h>
#include<qgsmessagelogviewer.h>
#include<qgsmessagelog.h>
#include<qgsattributetablefiltermodel.h>
#include<qgsmaptoolidentify.h>
#include<qgsprocessingregistry.h>
#include<qgsmaptooldigitizefeature.h>
#include<qgsadvanceddigitizingdockwidget.h>
#include<QgsBrowserGuiModel.h>
#include<QgsBrowserDockWidget.h>
#include<qgsdataitemproviderregistry.h>
//#include<qgsattributetabledialog.h>

//#include<qgssettings.h>
#include<qgsprocessingtoolboxmodel.h>
#include<qgsprocessingtoolboxtreeview.h>
#include<qgsnativealgorithms.h>

#include"rgsmaptoolidentifyaction.h"
class RgsMapToolAddFeature;

//修改后的qgs源文件
#include"qgsguivectorlayertools.h"



//qt头文件
#include<QHBoxLayout>
#include<QVBoxLayout>
#include<QFileSystemModel>
#include<QHeaderView>
#include<QLabel>
#include<QLineEdit>
#include<QDebug>
#include<qdebug.h>
#include<QStackedWidget>
#include<QShortcut>
#include<QKeySequence>
#include<QStringLiteral>
#include<QString>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class Riskgis : public QMainWindow
{
    Q_OBJECT

public:
    Riskgis(QWidget *parent = nullptr);
    ~Riskgis();
    static Riskgis* instance() { return rgs_instance; }

private:
    Ui::MainWindow *ui;

public:
    void updateCanvasLayer();
    void inittreeviewdock();
    void initMapCanvas();
    void initMessageLogViewer();
    void createMapTools();
    void initfiledock();
    void initstatusbar();
    void riskcreatoverview();
    void initAdvanceDigitizingDockWidget();
public:
    static Riskgis* rgs_instance;

signals:
    void emitmessage(const QString &title, const QString &message);
protected:

    // 画布
    QgsMapCanvas mMapCanvas;

    // 图层树 View
    QgsLayerTreeView mLayerTreeView;
    QgsLayerTreeMapCanvasBridge* layerTreeCanvasBridge;

    //图层树Dock
    QgsDockWidget* treeviewdock;

    //文件浏览视图
    QgsBrowserGuiModel* mBrowserModel;
    QgsBrowserDockWidget* mBrowserWidget;


    // 地图工具
    QgsMapTool* m_mapToolZoomIn;
    QgsMapTool* m_mapToolZoomOut;
    QgsMapTool* m_mapToolZoomFull;
    QgsMapTool* m_mapToolPan;
    QgsMapTool* m_mapToolIdentify;

    RgsMapToolAddFeature* m_mapToolAddFeature;

    QList<QgsMapLayer*> layers;
    int mapcanvas_crs;

    //statusbar控件
    QLineEdit* xcoordinates;
    QLineEdit* ycoordinates;
    QLabel* xlabel;
    QLabel* ylabel;
    QLabel* m_scaleLabel;
    QgsScaleComboBox* m_scaleEdit;
    QProgressBar* m_progressBar;
    //
    QgsMessageBar* m_infoBar;
    QStackedWidget* m_stackedWidget;

    //鹰眼图
    QgsDockWidget* m_overviewdock;
    QgsMapOverviewCanvas* m_overviewcanvas;
    QCursor* m_overviewmapcursor;
    QgsDockWidget* cc;

    //messageviewdock
    QgsDockWidget* messagedock;
    QgsMessageLogViewer* general;

    //AdvancedDigitizingDockWidget
    QgsAdvancedDigitizingDockWidget* mAdvancedDigitizingDockWidget;
    QMenu* _Panels;

    //VectorLayerTools
    QgsVectorLayerTools* mVectorLayerTools;

protected:
    void setTitle();
    void closeProject();
    void markDirty();
    void saveDirty();
    bool saveProject();

protected:
    void dragEnterEvent(QDragEnterEvent *event);
    void dropEvent(QDropEvent *event);
    void histogramStretch(bool visibleAreaOnly = false, QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax);
    QgsMessageBar* visibleMessageBar();
    void adjustBrightnessContrast(int delta, bool updateBrightness = true );
    void adjustGamma( double delta );
    void test_qgsfunction();
private:
    QStringList formatList;
    void initformatlist();

public:
    void addrasterlayer(QString filename);
    void addvectorlayer(QString filename);
    bool toggleEditing(QgsMapLayer* layer);
    bool toggleEditingVectorLayer(QgsVectorLayer* layer);
    void commitError( QgsVectorLayer *vlayer, const QStringList &commitErrorsList );
    QgsMessageBar* messageBar();

    QgsLayerTreeView* GetLayerTreeView();

    QgsMapCanvas* mapCanvas();
    //图层属性表
    void attributeTable(QgsAttributeTableFilterModel::FilterMode filter=QgsAttributeTableFilterModel::ShowAll,
                        const QString &filterExpression="");
    QgsMapLayer* activeLayer();
    void activateDeactivateRelatedAction(QgsMapLayer* layer);


    QgsAdvancedDigitizingDockWidget* cadDockWidget();
    QgsVectorLayerTools *vectorLayerTools() { return mVectorLayerTools; }
    void freezeCanvases(bool frozen=true);
    QList<QgsMapCanvas *> mapCanvases();
    QgsAttributeEditorContext createAttributeEditorContext();


public slots:


private slots:
    void on_actionaddRasterLayers_triggered();

    void on_actionaddVectorLayers_triggered();
    void on_actionRemoveGroupOrLayer_triggered();

    void on_actionRenameGroupOrLayer_triggered();

    void on_actionMapToolPan_toggled(bool arg1);
    void showMousePoint(const QgsPointXY &p);
    void userScale();
    void on_actionzoomin_toggled(bool arg1);
    void showScale(double theScale);

    void on_actionopenattributeTable_triggered();
    void on_actionzoomout_toggled(bool arg1);
    void on_actionzoomfull_triggered();
    void on_actionlocalCumulativeCutStretch_triggered();
    void on_actionfullCumulativeCutStretch_triggered();
    void on_actionlocalHistogramStretch_triggered();
    void on_actionfullHistogramStretch_triggered();
    void on_actionincreaseBrightness_triggered();
    void on_actiondecreaseBrightness_triggered();
    void on_actionincreaseContrast_triggered();
    void on_actiondecreaseContrast_triggered();
    void on_actionincreaseGamma_triggered();
    void on_actionspecialtest_triggered();
    void actionspecialtestslot(const QgsFeature& f);
    void on_actiondecreaseGamma_triggered();
    void on_actionattributetable_triggered();
    void on_actionmActionIdentify_toggled(bool arg1);
    void on_actiontoggleEditing_toggled(bool arg1);
    void on_mActionAddFeature_triggered();
};
#endif // RISKGIS_H
